package com.itboye.pondteam.utils;

import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by Administrator on 2017/3/22.
 */

public class MyTimeUtil {
    public static String parseTime1(String time) {
        long innerTime = Long.parseLong(time) * 1000;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd,HH:mm");
        return simpleDateFormat.format(innerTime);
    }

    public static String getCurrentTime(String time, String pattern) {
        long innerTime = Long.parseLong(time);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(innerTime);
    }

    public static String parseTime2(String time) {
        long innerTime = Long.parseLong(time) * 1000;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        return simpleDateFormat.format(innerTime);
    }

    public static String parseTime3(String time) {
        long innerTime = Long.parseLong(time) * 1000;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mm:ss");
        return simpleDateFormat.format(innerTime);
    }

    public static String getWeek(long time) {
        return new SimpleDateFormat("HH:mm:ss:EEEE").format(time);
    }

    public static int getTimeZone() {

        // 取得本地时间：
        Calendar cal = Calendar.getInstance();
        // 取得时间偏移量：
        int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);
        // 取得夏令时差：
        int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);
        cal.setTimeZone(TimeZone.getDefault());
//        TimeZone tz = TimeZone.getDefault();
//        int offset = tz.getRawOffset();//獲取当前手机时间与默认时间的偏移量
        int timeZone = (zoneOffset + dstOffset) / (3600 * 1000);//化为小时TimeZoneAndroid
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTimeZone(TimeZone.getDefault());
//        int dstOffset = calendar.get(Calendar.DST_OFFSET) / (1000 * 60 * 60);
//        if (timeZone < 0) {
//            timeZone = timeZone + dstOffset;
//        } else {
//            timeZone = timeZone - dstOffset;
//        }
        LogUtils.v("next_time", timeZone + "   timeZone");
        return timeZone;
    }


    private static int dateParseTest(String timeZoneId, String strTime, String pattern) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        // 指定传入的yyyyMMdd是哪个时区的时间
        sdf.setTimeZone(TimeZone.getTimeZone(timeZoneId));
        Date time = sdf.parse(strTime);
        LogUtils.v("next_time", time.toString() + " hours:" + time.getHours());
        return time.getHours();
    }


    public static int getCurrentHour() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
        return Integer.parseInt(simpleDateFormat.format(System.currentTimeMillis()));
    }


    public static  String caculcateSeconds(int fcd) {
        int h = 0;
        int d = 0;
        int s = 0;
        int temp = fcd % 3600;
        if (fcd > 3600) {
            h = fcd / 3600;
            if (temp != 0) {
                if (temp > 60) {
                    d = temp / 60;
                    if (temp % 60 != 0) {
                        s = temp % 60;
                    }
                } else {
                    s = temp;
                }
            }
        } else {
            d = fcd / 60;
            if (fcd % 60 != 0) {
                s = fcd % 60;
            }
        }
        return (h < 10 ? "0" + h : h) + ":" + (d < 10 ? "0" + d : d) + ":" + (s < 10 ? "0" + s : s);
    }


}
